use std::{borrow::Borrow, rc::Rc, sync::{Arc, Mutex}, time::Duration};

use job_scheduler_ng::{Job, JobScheduler};

// #[test]
pub fn test_job_scheduler(){
    println!("test_job_scheduler");
    let mut sched = JobScheduler::new();
    
    sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
        println!("I get executed every 10 seconds!");
    }));
    let i = 1;
    let i =  Arc::new(Mutex::new(i));
    let ic = i.clone();
    sched.add(Job::new("1/1 * * * * *".parse().unwrap(), move || {
        let mut lock = ic.lock().unwrap();
        println!("one second pass! i={}", lock);
        *lock += 1;
    }));
    println!("i={}", i.lock().unwrap());

    let mut idx = 1;
    loop {
        //睡眠知道下次任务到来
        std::thread::sleep(sched.time_till_next_job());
        sched.tick();

        idx+=1;
        if idx == 25 {
            break;
        }
    }
}